// ==UserScript==
// @name         关闭知乎登录弹出
// @version      1.0.3
// @description  自动关闭知乎登录框。包括中间、右上角、右下角的登录弹窗
// @author       Doubly
// @include      https://*.zhihu.com*
// @icon         https://static.zhihu.com/heifetz/favicon.ico
// @grant        none
// @downloadURL  https://gitee.com/doubly/tampermonkey-script/raw/master/ZhiHuLogin.user.js
// @updateURL    https://gitee.com/doubly/tampermonkey-script/raw/master/ZhiHuLogin.user.js
// @website     https://gitee.com/doubly/tampermonkey-script/tree/master
// ==/UserScript==

(function() {
    'use strict';

    // 清除中间的登录遮罩层
    let loginInterval = setInterval(()=>{
        let loginEl = document.getElementsByClassName('signFlowModal-container')[0];
        if(loginEl){
            console.log('检测到登录弹出');
            var keyboardEvent = new KeyboardEvent('keydown',{'keyCode':27,'which':27});
            document.dispatchEvent(keyboardEvent);
            clearInterval(loginInterval);
        }
    },100);

    // 清除右上角的登录弹出
    let rightTopInterval = setInterval(function () {
        let el = document.getElementsByClassName('css-1hwwfws')[0];
        if(el){
            console.log('检测到右上角弹出');
            el.remove();
            clearInterval(rightTopInterval);
        }
    },100)

    // 清除右下角的弹出
    let rightBottomInterval = setInterval(function () {
        let el = document.getElementsByClassName('css-1ynzxqw')[0];
        if(el){
            console.log('检测到右下角登录弹出');
            el.remove();
            clearInterval(rightBottomInterval);
        }
    },100)
})();